Ext.define('AM.view.JobView', {
		extend: 'Ext.grid.Panel',
		alias : 'widget.jobView',
//			initComponent: function(){
//		Ext.apply(this,{
		store : 'JobStore',
		columnLines:true,
//		selModel : Ext.create('Ext.selection.CheckboxModel'), 
		selModel: {
	        injectCheckbox: 0,
	        mode: "SIMPLE"    //"SINGLE"/"SIMPLE"/"MULTI"
	        
   		 },
   		selType: "checkboxmodel",
    	dockedItems: [{
	        xtype: 'pagingtoolbar',
	        dock: 'bottom',
	        store : 'JobStore',
	        displayInfo: true
        }],
		columns: [
			        { text: '序号', width:50,align:'center',xtype: 'rownumberer'},
			        { text: '名称', dataIndex: 'name', width:120,align:'center'},
			        { text: '创建日期', dataIndex: 'creatDate',  width:100,align:'center',xtype: 'datecolumn',format:'Y-m-d',  sortable: true},
			        { text: '创建人',  dataIndex: 'employee.name',  width:100,align:'center'},
			        { text: '得分',dataIndex: 'core', width:80,align:'center' },
			        { text: '类型',dataIndex: 'jobstyle', width:160,align:'center',renderer: function(value){
					        	 if (value === 2) {
										 return '临时性工作';
								 }if (value === 1) {
										 return '创新性工作';
								 }
						}
			        },
			        { text: '状态',dataIndex: 'state', width:80,align:'center',renderer: function(value){
								 if (value === 1) {
										  return '<span style="color:purple;">未发布</span>'; 
								 }if (value ===2) {
								 	  return '<span style="color:green;">办理中</span>';
								 }if (value === 3) {
										return '<span style="color:red;">结束</span>';
								 }						 
						 }
			        },
			        { text: '操作', dataIndex: 'id',width:280,align:'center',renderer : function(data, cell, record, rowIndex,columnIndex){
			        	    var resultStr = "<div class='controlBtn'>" +     
                            "<a href='javascript:void("+record.get('id')+");  'class='alarm_detail 'onclick='addDetail("+record.get('id')+")'>添加详细</a>&nbsp;&nbsp;&nbsp;&nbsp;" +     
                            "<a href='javascript:void("+record.get('id')+"); 'class='alarm_detail  'onclick='listJobdetail("+record.get('id')+")'>查看详情</a>&nbsp;&nbsp;&nbsp;&nbsp;" +  
                            "<a href='javascript:void("+record.get('id')+"); 'class='alarm_detail  'onclick='FabuJob("+record.get('id')+")'>发布流程</a>&nbsp;&nbsp;&nbsp;&nbsp;"+
                             "<a href='javascript:void("+record.get('id')+"); 'class='alarm_detail 'onclick='QuxiaoFubuJob("+record.get('id')+")'>取消发布</a>"
                            "</div>";     
         					 return resultStr;  
			       		  }
         	    	}
				],
			   tbar: [
					  { xtype: 'button',id:'tab-78_add', text: '增加',handler: addJob,icon: 'Ext/restful/images/add.png'
					  },
					  { xtype: 'button',id:'tab-78_edit',text: '修改',handler:editJob,icon: 'Ext/restful/images/cog_edit.png'
					  },
					  { xtype: 'button',id:'tab-78_delete', text: '删除',handler:deletJob,icon: 'Ext/restful/images/delete.png'
					  },
					  '->',
					  {  xtype : "datefield",
						 fieldLabel: '查询日期',
						 labelWidth:60,
						 name: 'searchdate',
						 format:'Y-m-d',
						 id:'searchjob_999'
					  },
					  { xtype: 'button', text: '查询',id:'tab-78_search',handler:searchJob,icon : 'Ext/restful/images/find.png'
					  }
					  
					]
//							});
//	  this.callParent(arguments);
//  	}
})
		   
//发布工作
   function QuxiaoFubuJob(id){
   			Ext.Ajax.request({
					url : 'job_quxiaofabu',
					success : function() {
						jobView=Ext.create('AM.view.JobView')
						jobView.getStore().reload();
					},
					failure : function() {
						Ext.MessageBox.alert("提示", "项目已经完成！");
					},
					params : {
							id:id	
					}
		});	
   
   }
 //取消发布
  function FabuJob(id){
   			Ext.Ajax.request({
					url : 'job_fabu',
					success : function() {
						jobView=Ext.create('AM.view.JobView');
						jobView.getStore().reload();
					},
					failure : function() {
						Ext.MessageBox.alert("提示", "项目正在办理中或已经完成！");
					},
					params : {
							id:id	
					}
		});	
   
   }
//添加详情
function addDetail(id){ 
	    jobView=Ext.create('AM.view.JobView');
		var selections = jobView.getSelectionModel().getSelection();
		var name = selections[0].data.name;
    var jobId=id;
	Ext.Ajax.request({
			url : 'job_addJobdetail',
			success : function() {
				Ext.Ajax.request({
					url : 'jobDetail_ListJobDetail',
					success : function() {
							  Ext.getCmp('mygrid1').getStore().on('beforeload', function (store, options) {
                              var new_params = {jobId:jobId}
                                    Ext.apply(store.proxy.extraParams, new_params);
                           });//此处为加载条件
							  Ext.getCmp('mygrid1').getStore().reload();
							  win.show();
						},
					failure : function() {
							Ext.MessageBox.alert("提示", "暂无工作详情！");
									}
				});		
		var myform= new Ext.form.Panel({
//			     	id:'form',
//			        width : 990, 
//			        autoHeight : true,
			        layout : "form",
			        labelWidth : 65,
			        items: [{
						layout : "column",
						border : false,
						items: [{
					        	columnWidth :.50,
								layout : "form",
								border : false,
					   			items: [{
					   				    xtype : "textfield",
					   				    fieldLabel: '步骤名称',
					   				    labelAlign :"right",
							            name: 'name',
							            value:name
							        }]		        	
				        		},{ 
					        	columnWidth :.20,
					        	layout : "form",
					        	border : false,
							    items:[{
							      	    xtype : "numberfield",
							      		labelAlign :"right",
							            fieldLabel: '步骤',
							            name: 'step',
							            allowBlank:false,
							            blankText:"不能为空，必须为数字",
							            minValue: 1
							            
							        }]
				        		}]
				        },{
					         layout : "column",
					         border : false,			 
						     items: [{
							        	columnWidth :.25,
										layout : "form",
										border : false,
							   			items: [{
							   				    xtype : "datefield",
							   				    labelAlign :"right",
							   				    fieldLabel: '开始时间',
									            name: 'startdate',
									            format:'Y-m-d',
									            width:30,
									            listeners: {
															select :function( field, value, eOpts ){     
																        var parent=Ext.getCmp('planCompleteDate');
																		 parent.setValue(value);	 
														        }
												        }
									        }]		        	
						        		},{
						        		   columnWidth :.25,
										   layout : "form",
										   border : false,
									   	   items: [{
									   				    xtype : "datefield",
									   				    labelAlign :"right",
									   				    fieldLabel: '计划完成时间',
											            name: 'planCompleteDate',
											            format:'Y-m-d',
											            id:"planCompleteDate",
											            width:30
									       			 }]		
							        		
								    },{
								     columnWidth :.20,
								     layout : "form",
									 border : false,
											 items: [{
									   				    xtype : "numberfield",
									   				    labelAlign :"right",
									   				    nanText:"请输入0到1之间的小数",
									   				    fieldLabel: '步骤得分比',
									   				    allowBlank:false,
							         				    blankText:"不能为空，必须为数字",
									   				 	step :2,
									   				 	name:'buzhoubili',
							        				    maxValue: 100,
														minValue: 1
									  		  }]
								  }]
					    },{
							 layout : "column",
							 id:'deptanddepart',
							 border : false,
							 items: [{
								       columnWidth :.25,
								       layout : "form",
								       border : false,
									   items:[{
													xtype : "combobox",
										      	    emptyText:'请选择科室',
										      	    selectOnFocus:true,
										      	    id:'depart',
													forceSelection: true,
										      	    labelAlign :"right",
										            fieldLabel: '科室',
										            queryMode: 'local',
										            triggerAction:'all', 
//										            multiSelect:true, //多选
										            name: 'depar',
										            store :"TargetDepartStore",
										            displayField: 'name',
	    											valueField: 'name',
										            listeners:{   
																select:function(combo, record,index){
																	 try{
																		 var parent=Ext.getCmp('person');
																		 parent.clearValue();
																		 parent.store.load({params:{param:this.value}});
																	 }
																	 catch(ex){
																		 Ext.MessageBox.alert("错误","数据加载失败。");
																	 }
																}
															}
											 }]						        		           	
									},{
							        	columnWidth :.25,
							        	layout : "form",   
							            border : false,
									    items:[{
										        	 fieldLabel: '岗位—人员',
										        	 emptyText:'请选择人员',
										      	     xtype:"combobox",
										      	     labelAlign :"right",
										      	     selectOnFocus:true,
													 forceSelection: true,
//										      	     multiSelect:true,//多选
//										      	     triggerAction:'all', 
										      	     queryMode: 'local',
										      	     id:'person',
										      	     name: 'empl',
										      	     store :"SearchAddJobEmpStore",
										             displayField: 'name',
	    											 valueField: 'name'
										        }]
									},{
										 columnWidth :.20,
									     layout : "form",
									     border : false,
									     items: [{
									   			     xtype : "numberfield",
									   				 labelAlign :"right",
									   				 fieldLabel: '个人得分比',
									   				 blankText:"必须为数字",
									   				 minValue: 0,
											         name: 'personbili',
											         id:'personbili'
									       }]	
										
									},{	
							        	columnWidth :.15,
									    border : false,
							            layout : "form",
							            items:[{
							        	        xtype: 'checkboxfield',
										        labelAlign :"right",
							                    fieldLabel: '是否同步',
											    name: 'flag',
							                    inputValue: '1',
							                    hidden:true,
							                    checked: false,
												id :'wkHobbys'
											}]
									},{
										columnWidth :.03,
									    border : false,
							            layout : "form",
							            items:[{
							        	       border : false
											}]
									},{ 
										columnWidth :.15,
									    layout : "form",
									    border : false,
									    items:[{
										      	   xtype:'button',
										      	   labelAlign :"right",
										      	   text:'继续添加',
										      	   handler:function(){
										      	   Ext.getCmp('textthis').setVisible(true);
										      	   var val=Ext.getCmp('depart').getValue();
										      	   var values=Ext.getCmp('person').getValue();
										      	   var va= Ext.getCmp('textthis').getValue();
										      	   var b= Ext.getCmp('personbili').getValue();
										      	   Ext.getCmp('textthis').setValue(va+"["+val+"-"+values+"-"+b+"]"+",");
										      	   var parent=Ext.getCmp('person');
												   parent.clearValue();
												   var son=Ext.getCmp('depart');
												   son.clearValue();
												   var bb=Ext.getCmp('personbili');
												   bb.reset();
										      	   }
									}]
								}]
						 },{
						 	 layout : "column",
						 	 border : false,
							        	items: [
							        		{
							        		    columnWidth :.8,
												layout : "form",
												border : false,
									   			items: [{
									   				    xtype : "textfield",
									   				    hidden : true,
									   				    id:'textthis',
									   				    labelAlign :"right",
									   				    fieldLabel: '已添加',
											            name: 'had' 
											            
									       			 }]		        	
							        		}]					 
						 }
						 ,{
							    layout : "column",
						         border : false,			 
							     items: [ {
								        	columnWidth :.30,
								        	layout : "form",
								        	border : false,
										    items:[{
											      	  xtype: 'filefield',
								                     labelAlign:'right',
								                     name: 'upload',
								                     msgTarget: 'side',
								                     buttonText:'浏览...',
								                     fieldLabel: '添加附件'
										        }]
							        	
							        	}]
						 },
						 	{
						 	 layout : "column",
					         border : false,			 
						     items: [ {
							        	columnWidth :.75,
							        	layout : "form",
							        	border : false,
									    items:[{
									      	    xtype : "textarea",
									      	    labelAlign :"right",
									            fieldLabel: '工作要求',
									            name: 'jobRequirement',
									            height : 60
									        }]
						        	
						        	},{
						        		columnWidth :.1,
										layout : "form",
										border : false,
									   	items: [{
									   		      xtype : "textfield",
									   			  labelAlign :"right",
									   			  fieldLabel: '所属项目',
											      name: 'job.id',
											      value: jobId,
											      hidden:true
							        	  }]
						        	},{
						        		columnWidth :.10,
										layout : "form",
										border : false,
									   	items: [{
									   			  xtype : "textfield",
									   			  labelAlign :"right",
									   			  fieldLabel: '状态',
											      name: 'state',
											      value: 1,
											      hidden:true         
							        	  }]
						        	}]
	
						 }],
			        	buttons : [{
							text : "添加步骤",
							handler : function() {	
							var n=2;
								//获取checkbox中的值
							var FileItype=win.getComponent(0).getForm().findField('wkHobbys').getValue();
								 if(FileItype==true){
								 n=1;
							 }                     
							  win.getComponent(0).getForm().submit({
										url : 'jobDetail_addJobDetail',
										baseParams:{flag:n},
										success : function() {					
											Ext.Msg.alert('提示', '添加成功');
											//win.getComponent(0).getForm().updateLayout(true);
											win.getComponent(0).getForm().reset();
											Ext.getCmp('mygrid1').getStore().reload();
											myform.remove(fd,false);  
										    win.remove(Ext.getCmp('deptanddepart'));
											myform.doLayout();	  
										},
										failure : function() {
											Ext.Msg.alert('错误', '添加失败，请检查填写是否正确');
										},
											waitMsg : "请稍后，正在保存。。。。"										
						    	});
						   }
						}, {
							text : "重置",
							handler : function() {
								win.getComponent(0).getForm().reset();
							}
						}]
			    });
	  var mygrid1=Ext.create('Ext.grid.Panel', {
				    id:'mygrid1',
				    height: 215,
					width: 990,
				    columnLines:true,
				    store:'JobDetailStore',
				    selModel : Ext.create('Ext.selection.CheckboxModel'), 
				    columns: [
						    { text: '序号', width:50,align:'center',xtype: 'rownumberer'},
						    { text: 'ID',dataIndex: 'id',width:0,align:'center'},
					        { text: '名称', dataIndex: 'name', width:100,align:'center'},
					        { text: '所属项目', dataIndex:'job.name', width:100,align:'center'},
					        { text: '步骤', dataIndex: 'step', width:50,align:'center'},
					        { text: '科室',  dataIndex: 'department.name',  width:90,align:'center' },
					        { text: '人员',dataIndex: 'employee.name', width:80,align:'center' },
					        { text: '开始时间', dataIndex: 'startdate', width:90,align:'center',xtype: 'datecolumn',format:'Y-m-d'},
					        { text: '计划完成时间',  dataIndex: 'planCompleteDate',  width:100,align:'center',xtype: 'datecolumn',format:'Y-m-d' },
					        { text: '得分',dataIndex: 'core', width:50,align:'center' },
					        { text: '要求', dataIndex: 'jobRequirement', width:150,align:'center'}
//					        { text: '备注',dataIndex: 'remark', width:200,align:'center' }
				    	 ],
				   tbar: [
						  { xtype: 'button', text: '修改步骤',handler:editJobDetail,icon: 'Ext/restful/images/cog_edit.png'
						  },
						  { xtype: 'button', text: '删除步骤',handler:deletJobDetail,icon: 'Ext/restful/images/delete.png'
						  }
						]
				});
		var win = new Ext.Window({
				        title : "添加步骤",
					    width : 1000,
					    height : 530,
						closable : true,
					    draggable : true,
					    frame:true,
					    modal: true,
					    minimizable:true,
					    maximizable:true, 
	//	       								    resizable : false,
					    layout : 'anchor',
					    plain : true,
					    items: [ myform,
					    		 mygrid1
					    ],
					      buttons : [{
								text : "确定",
									handler : function() {	
											win.close();
									}												
								},{
								  text : "取消",
								  handler : function() {
//										Ext.Ajax.request({
//											url : 'jobDetail_deleteByJobId',
//											failure : function() {
//												Ext.MessageBox.alert("提示", "项目具体内容未删除完全！");
//											},
//											params : {
//												jobId:jobId	
//											}
//										});		
										win.close();			
									}
							},{
								  text : "删除所有",
								  handler : function() {
										Ext.Ajax.request({
											url : 'jobDetail_deleteByJobId',
											failure : function() {
												Ext.MessageBox.alert("提示", "项目具体内容未删除完全！");
											},
											params : {
												jobId:jobId	
											}
										});		
										win.close();			
									}
							}]
						}).show();						
						
				},
			failure : function() {
						Ext.MessageBox.alert("提示", "项目正在办理中或已经完成！");
			},
			params : {
					  jobId:jobId	
					}
		});	
		
		   	
	function deletJobDetail(){
				 var grid=this.ownerCt.ownerCt;
			     var selections = grid.getSelectionModel().getSelection();
					if(selections){
					if(selections.length==0){
							Ext.MessageBox.alert("提示","请检查是否选中某一行！");
						}else if (selections.length > 1) {
							Ext.MessageBox.alert("提示", "请检查您是否选中了多行！");
							return;
						} else{
							Ext.MessageBox.confirm("提示", "确认要删除 ？", function(btn) {
							if (btn == 'yes') {			
							var record = selections[0];
								Ext.Ajax.request({
										url : 'jobDetail_deletejobDetail',
										success : function() {
											Ext.MessageBox.alert("提示",
													"删除" + record.get("name")+ "成功！");
												Ext.getCmp('mygrid1').getStore().remove(selections );
												Ext.getCmp('mygrid1').getStore().reload();
										},
										failure : function() {
											Ext.MessageBox.alert("提示", "删除失败！");
										},
										params : {
											id : record.get("id")
										}
									});			
								}
					  	})
                   	} 
 			   
		   }				
	}										
// 修改工作步骤									
	function editJobDetail(){
		    var myform= new Ext.form.Panel({
			        layout : "form",
			        labelWidth : 65,
			        items: [{
			        layout : "column",
			        border : false,
			        	items: [{
					        	columnWidth :.46,
								layout : "form",
								border : false,
								labelWidth : 30,
					   			items: [{
					   				    xtype : "textfield",
					   				    fieldLabel: '步骤名称',
					   				    labelAlign :"right",
							            name: 'name',
							            blankText:"不能为空",
							            allowBlank:false,
							            width:30
							        }]		        	
				        		},{ 
					        	columnWidth :.30,
					        	layout : "form",
					        	 border : false,
							    items:[{
							      		xtype : "numberfield",
							      		labelAlign :"right",
							            fieldLabel: '步骤',
							            name: 'step',
							            allowBlank:false,
							            blankText:"不能为空，必须为数字",
							            minValue: 1,
							            width:20 
							        }]
				        		}]
				        },{
					         layout : "column",
					         border : false,			 
						     items: [{
							        	columnWidth :.46,
										layout : "form",
										border : false,
							   			items: [{
							   				    xtype : "datefield",
							   				    labelAlign :"right",
							   				    fieldLabel: '开始时间',
									            name: 'startdate',
									            format:'Y-m-d',
									            width:30
									        }]		        	
				        
						        		},{
						        		   columnWidth :.46,
										   layout : "form",
										   border : false,
									   	   items: [{
									   				    xtype : "datefield",
									   				    labelAlign :"right",
									   				    fieldLabel: '计划完成时间',
											            name: 'planCompleteDate',
											            format:'Y-m-d',
											            width:30
									       			 }]		
							        		
							        }]
						 },{
				   		 	 layout : "column",
				   		 	 columnWidth :.40,
						 	 border : false,
							        	items: [{
							        		 columnWidth :.46,
							        	     layout : "form",
							        	     border : false,
										     items:[{
										      	    xtype : "combobox",
										      	    labelAlign :"right",
										            fieldLabel: '科室',
										            allowBlank:false,
										            name: 'department.id',
										            store :"TargetDepartStore",
										            displayField: 'name',
	    											valueField: 'id',
										            width:30,
										            listeners:{   
																select:function(combo, record,index){
																	 try{
																		 var parent=Ext.getCmp('emp_121');
																		 parent.clearValue();
																		 parent.store.load({params:{param1:this.value}});
																	 }
																	 catch(ex){
																		 Ext.MessageBox.alert("错误","数据加载失败。");
																	 }
																}
															}
										        }]						        		           	
							        		},{
							        			columnWidth :.46,
							        	        layout : "form",
							        	        border : false,
										        items:[{
										      	    xtype:"combobox",
										      	    labelAlign :"right",
										      	    queryMode: 'local', 
										            fieldLabel: '人员',
										            id:'emp_121',
										            allowBlank:false,
										            name: 'employee.id',
										            store :"SearchEmpStore",
										            displayField: 'name',
	    											valueField: 'id',
												    width:30
										        }]
			   							 }]
						 },{
						 	 layout : "column",
						 	 border : false,
							        	items: [{
							        		    columnWidth :.30,
												layout : "form",
												border : false,
									   			items: [{
									   				    xtype : "numberfield",
									   				    labelAlign :"right",
									   				    fieldLabel: '得分',
									   				    blankText:"必须为数字",
									   				    minValue: 0,
									   				    readOnly : true,
											            name: 'core' 
									       			 }]		        	
							        		},{
							        			columnWidth :.46,
												layout : "form",
												border : false,
									   			items: [{
									   				    xtype : "textfield",
									   				    labelAlign :"right",
									   				    fieldLabel: 'JobDtetaiId',
											            name: 'id',
											            hidden:true
											            
							        			  }]
			   							 }]
						 },{
						 	 layout : "column",
					         border : false,			 
						     items: [ {
							        	columnWidth :.75,
							        	layout : "form",
							        	border : false,
									    items:[{
									      	    xtype : "textarea",
									      	    labelAlign :"right",
									            fieldLabel: '工作要求',
									            name: 'jobRequirement',
									            width:30
									        }]
						        	
						        	},{
						        		columnWidth :.46,
												layout : "form",
												border : false,
									   			items: [{
									   				    xtype : "textfield",
									   				    labelAlign :"right",
									   				    fieldLabel: '所属项目',
											            name: 'job.name',
											            hidden:true
							        			  }]
						        	}]
	
						 }]
			    });
		
			var win = new Ext.Window({
				title : "修改步骤",
				width : 700,
				height : 350,
				frame:true,
				layout:'fit',
				items : [ myform
							],
				buttons : [{
							text : "确定",
							handler : function() {
								win.getComponent(0).getForm().submit({
											    url : 'jobDetail_updatejobDetail',
											    success : function() {
												Ext.Msg.alert('提示', '修改成功');
												win.close();
												Ext.getCmp('mygrid1').getStore().reload();
												Ext.getCmp('mygrid1').getSelectionModel().deselectAll();//去除选择
											},
											failure : function() {
												Ext.Msg.alert('错误', '修改失败，请检查填写是否正确');
											},
											waitMsg : "请稍后，正在保存。。。。"
	
										});
							}
						}, {
							text : "重置",
							handler : function() {
								win.getComponent(0).getForm().reset();
							}
						}, {
							text : "取消",
							handler : function() {
												win.close();
											
							}
						}]
			});
		var grid=this.ownerCt.ownerCt;
		var selections = grid.getSelectionModel().getSelection();
						if(selections.length==0){
							Ext.MessageBox.alert("提示","请选择要编辑的一行！");
						}else if (selections.length > 1) {
							Ext.MessageBox.alert("提示", "请检查您是否选中了多行！");
							return;
						} else{
							var record = selections[0];
						//这里是修改操作的实现部分
							win.getComponent(0).getForm().loadRecord(record);
							win.show();
						}
 	}																		
}	
	 	 	
	 	//查看工作详情
	function listJobdetail(id){
		   var jobId=id;
			Ext.Ajax.request({
					url : 'jobDetail_ListJobDetail',
					success : function() {
						//此处为加载条件
						  Ext.getCmp('mygrid').getStore().on('beforeload', function (store, options) {
                            	 var new_params = { jobId:jobId}
                            	 Ext.apply(store.proxy.extraParams, new_params);
                		  });
						  Ext.getCmp('mygrid').getStore().reload();
						  win.show();
					},
					failure : function() {
						Ext.MessageBox.alert("提示", "查询失败！");
					}
//										params : {
//											jobId:jobId	
//										}
				});			

	
	 var mygrid=Ext.create('Ext.grid.Panel', {
				    id:'mygrid',
				    width : 990,
				    columnLines:true,
				    store:'JobDetailStore',
				    plugins: [{
			            ptype: 'rowexpander',
			            rowBodyTpl : new Ext.XTemplate(
			                '<p><b>要求:</b> {jobRequirement}</p>',
			                '<p><b>备注:</b> {remark}</p><br>' 
			            )
			        }],
				    columns: [
				    { text: '序号', width:50,align:'center',xtype: 'rownumberer'},
			        { text: '名称', dataIndex: 'name', width:100,align:'center'},
			        { text: '所属项目', dataIndex:'job.name', width:120,align:'center'},
			        { text: '步骤', dataIndex: 'step', width:50,align:'center'},
			        { text: '科室',  dataIndex: 'department.name',  width:50,align:'center' },
			        { text: '人员',dataIndex: 'employee.name', width:50,align:'center' },
			        { text: '开始时间', dataIndex: 'startdate', width:80,align:'center',xtype: 'datecolumn',format:'Y-m-d'},
			        { text: '计划完成时间',  dataIndex: 'planCompleteDate',  width:100,align:'center',xtype: 'datecolumn',format:'Y-m-d' },
			        { text: '得分',dataIndex: 'core', width:50,align:'center' },
			        { text: '状态',  dataIndex:'state',  width:80,align:'center',renderer: function(value){
								 if (value === 1) {
										 return '未办理';
								 }if (value ===2) {
										 return '办理中';
								 }if (value === 3) {
										 return '结束';
								 }	
			       		 }
			        },
			        { text: '要求', dataIndex: 'jobRequirement', width:100,align:'center'},
			        { text: '备注',dataIndex:'remark',width:120,align:'center' }
				     ]
				});
	 	
	 	var win = new Ext.Window({
				title : "项目详情",
				width : 1000,
				height : 350,
				minimizable:true,
	    	    maximizable:true,
				frame:true,
				layout:'fit',
				items :[mygrid],
				buttons : [{
							text : "确定",
							handler : function() {
								win.close();
							}
						},{
							text : "关闭",
							handler : function() {
							win.close();
											
							}
						}]
			});
 }
	 	
 	
	//添加工作 	
	function addJob() {
		 var grid=this.ownerCt.ownerCt;
		 var myform1= new Ext.form.Panel({
			        width : 700, 
			        autoHeight : true,
			        layout : "form",
			        labelWidth : 65,
			        items: [{
			        	layout : "column",
			       		border : false,
			        	items: [{
					        	columnWidth :.4,
								layout : "form",
								border : false,
								labelWidth : 30,
					   			items: [{
					   				    xtype : "textfield",
					   				    allowBlank:false,
					   				    fieldLabel: '项目名称',
					   				    blankText:"项目名称不能为空",
					   				    labelAlign :"right",
							            name: 'name',
							            width:30
							        }]		        	
				        		},{
				        			columnWidth :.45,
							        layout : "form",
							        border : false,
									       items:[{
									      	    xtype:"radiogroup",
									      	    labelAlign :"right",
									            fieldLabel: '项目类型',
									            name:'jobstyle',
									            id:"leixing",
									            columns: 2,
									            
        										vertical: true,
											    items: [
											                // { boxLabel: '创新性工作', name: 'jobstyle', inputValue: '1',id:'radio1',checked: true},
           													 { boxLabel: '临时性工作', name: 'jobstyle', inputValue: '2',id:'radio2',checked: true}
												  	]
//												 listeners:{  
//												 	'change':{
//												 		 fn: function(){
//												 		 	// var radio1 = Ext.getCmp('radio1'),
//												 		 	   	 radio2 = Ext.getCmp('radio2');
////												 		 	if(radio1.getValue()){
////												 		 		Ext.getCmp('fen').setVisible(false);
////												 		 		Ext.getCmp('jinjidu').setVisible(false);
////												 		 		Ext.getCmp('chuangxin').setVisible(true);	
//////												 		 		Ext.getCmp('dengji').setVisible(true);	
////												 		 	}
//												 		 	if(radio2.getValue()){
//												 		 		Ext.getCmp('fen').setVisible(true);
//												 		 		Ext.getCmp('jinjidu').setVisible(true);
//												 		 		Ext.getCmp('chuangxin').setVisible(false);
////												 		 		Ext.getCmp('dengji').setVisible(false);	
//												 		 	}
//												 		 													 		 		
//												 		 }
//												 	}
//												 }
									        }]
				        		}]
				        },{
					         layout : "column",
					         border : false,			 
						     items: [{
							        	columnWidth :.40,
										layout : "form",
										 border : false,
							   			items: [{
							   				    xtype : "datefield",
							   				    labelAlign :"right",
							   				    fieldLabel: '创建时间',
									            name: 'creatDate',
									            format:'Y-m-d',
									            width:30
									        }]		        	
						        		},{
						        			columnWidth :.60,
							        	    layout : "form",
							        	    border : false,
									       items:[{
									      	    xtype:"radiogroup",
									      	    labelAlign :"right",
									            fieldLabel: '项目状态',
									            name: 'state',
											    width:30,
											    hidden : true ,
									            columns: 3,
        										vertical: true,
											    items: [
											                 { boxLabel: '未办理', name: 'state', inputValue: '1',checked: true},
           													 { boxLabel: '办理中', name: 'state', inputValue: '2'  },
												             { boxLabel: '结束', name: 'state', inputValue: '3' }
												  	]
									            
									        }]
						        		
						        		}]
					  },{
			   		 	layout : "column",
					 	border : false,
							items: [{
							 	     columnWidth :.40,
							 		 layout : "form",
							 		 fieldLabel: '项目分数',
									 emptyText:'请选择得分',
									 xtype:"combobox",
								     labelAlign :"right",
								     id:"chuangxin",
								     selectOnFocus:true,
									 queryMode: 'local',
									 name: 'chaungxincore',
								     hidden : true ,
									 store :'ChuangxinCore',
									 displayField: 'core',
	    							 valueField: 'core' 
				   			 }]
			   		   },{
			   		 	 layout : "column",
					 	 border : false,
						 items: [{
							 		 columnWidth :.40,
							 		 layout : "form",
							 		 fieldLabel: '等级',
									 emptyText:'请选等级',
									 xtype:"combobox",
								     labelAlign :"right",
								     id:"jinjidu",
								     selectOnFocus:true,
									 queryMode: 'local',
//									 hidden : true ,
									 name: 'nanyi',
									 forceSelection: true,  
									 store :Ext.create('Ext.data.Store', {
												    fields: ['id','name'],
												    data : [
														      {"id":1, "name":"一级"},
														      {"id":2, "name":"二级"},
														      {"id":3, "name":"三级"},
												              {"id":4, "name":"四级"}
												        ]
										 		}),
									 displayField: 'name',
	    							 valueField: 'id',
	    							 listeners:{   
												select:function(combo,record,index){
													 try{
															 var parent=Ext.getCmp('fen');
															 parent.clearValue();
															 parent.store.load({params:{param:this.value}});
														 }
													 catch(ex){
																 Ext.MessageBox.alert("错误","数据加载失败。");
															 }
													}
											}
							          	        	
								},{
									 columnWidth :.40,
									 layout : "form",
									 emptyText:'请选择得分',
									 fieldLabel: '项目分数',
									 id:'fen',
//									 hidden : true ,
									 xtype:"combobox",
								     labelAlign :"right",
								     forceSelection: true,  
								     selectOnFocus:true,
									 queryMode: 'local',
									 name: 'core',
									 store :"CoreStore",
									 displayField: 'core',
	    							 valueField: 'core'
								}]	
			   		 }]
		 })
			var win = new Ext.Window({
				title : "添加工作",
				width : 700,
				height : 300,
				frame:true,
				layout:'fit',
				items : [ myform1
							],
				buttons : [{
							text : "确定",
							handler : function() {
								win.getComponent(0).getForm().submit({
											    url : 'job_addJob',
											    success : function() {
											    Ext.Msg.alert('提示', '添加成功');
											    win.close();
//											    Ext.getCmp('jobView').getStore().reload();//jobView 为id号
											    grid.getStore().reload();
											},
											failure : function() {
												Ext.Msg.alert('错误', '添加失败');
											},
											waitMsg : "请稍后，正在保存。。。。"
	
										});
							}
						}, {
							text : "重置",
							handler : function() {
								win.getComponent(0).getForm().reset();
							}
						}, {
							text : "取消",
							handler : function() {
												win.close();
											
							}
						}]
			});
		win.show();
	}
	//修改工作
	function editJob() {
		var grid=this.ownerCt.ownerCt;
		 var myform1= new Ext.form.Panel({
			        width : 700, 
			        autoHeight : true,
			        layout : "form",
			        labelWidth : 65,
			        items: [{
			        	layout : "column",
			       		border : false,
			        	items: [{
					        	columnWidth :.40,
								layout : "form",
								border : false,
								labelWidth : 30,
					   			items: [{
					   				    xtype : "textfield",
					   				    allowBlank:false,
					   				    fieldLabel: '项目名称',
					   				    blankText:"项目名称不能为空",
					   				    labelAlign :"right",
							            name: 'name',
							            width:30
							        }]		        	
				        		},{
				        			columnWidth :.45,
							        layout : "form",
							        border : false,
									       items:[{
									      	    xtype:"radiogroup",
									      	    labelAlign :"right",
									            fieldLabel: '项目类型',
									            name:'jobstyle',
									            id:"leixing",
									            columns: 2,
        										vertical: true,
											    items: [
//											                 { boxLabel: '创新性工作', name: 'jobstyle', inputValue: '1',id:'radio1',checked: true}
           													 { boxLabel: '临时性工作', name: 'jobstyle', inputValue: '2',id:'radio2',checked: true}
												  	]
//												 listeners:{  
//												 	'change':{
//												 		 fn: function(){
//												 		 	 var radio1 = Ext.getCmp('radio1'),
//												 		 	   	 radio2 = Ext.getCmp('radio2');
//												 		 	if(radio1.getValue()){
//												 		 		Ext.getCmp('fen').setVisible(false);
//												 		 		Ext.getCmp('jinjidu').setVisible(false);
//												 		 		Ext.getCmp('chuangxin').setVisible(true);	
////												 		 		Ext.getCmp('dengji').setVisible(true);	
//												 		 	}if(radio2.getValue()){
//												 		 		Ext.getCmp('fen').setVisible(true);
//												 		 		Ext.getCmp('jinjidu').setVisible(true);
//												 		 		Ext.getCmp('chuangxin').setVisible(false);
////												 		 		Ext.getCmp('dengji').setVisible(false);	
//												 		 	}
//												 		 													 		 		
//												 		 }
//												 	}
//												 }
									        }]
				        		}]
				        },{
					         layout : "column",
					         border : false,			 
						     items: [{
							        	columnWidth :.40,
										layout : "form",
										 border : false,
							   			items: [{
							   				    xtype : "datefield",
							   				    labelAlign :"right",
							   				    fieldLabel: '创建时间',
									            name: 'creatDate',
									            format:'Y-m-d',
									            width:30
									        }]		        	
						        		},{
						        			columnWidth :.60,
							        	    layout : "form",
							        	    border : false,
									       items:[{
									      	    xtype:"radiogroup",
									      	    labelAlign :"right",
									            fieldLabel: '项目状态',
									            name: 'state',
											    width:30,
											    hidden : true ,
									            columns: 3,
        										vertical: true,
											    items: [
											                 { boxLabel: '未办理', name: 'state', inputValue: '1',checked: true},
           													 { boxLabel: '办理中', name: 'state', inputValue: '2'  },
												             { boxLabel: '结束', name: 'state', inputValue: '3' }
												  	]
									            
									        }]
						        		
						        		}]
					  },{
			   		 	layout : "column",
					 	border : false,
							items: [{
							 	     columnWidth :.40,
							 		 layout : "form",
							 		 fieldLabel: '项目分数',
									 emptyText:'请选择得分',
									 xtype:"combobox",
								     labelAlign :"right",
								     id:"chuangxin",
								      hidden:true,
								     selectOnFocus:true,
									 queryMode: 'local',
									 name: 'chaungxincore',
									 store :'ChuangxinCore',
									 displayField: 'core',
	    							 valueField: 'core' 
				   			 },{
				   			 	 columnWidth :.40,
							 	 layout : "form",
				   			 	 xtype : "textfield",
			   				    allowBlank:false,
			   				    fieldLabel: 'ID',
			   				    labelAlign :"right",
					            name: 'id',
					            width:30,
					            hidden:true
					           
				   			 }]
					  },{
			   		 	 layout : "column",
					 	 border : false,
						 items: [{
							 		 columnWidth :.40,
							 		 layout : "form",
							 		 fieldLabel: '紧急度',
									 emptyText:'请选择程度',
									 xtype:"combobox",
								     labelAlign :"right",
								     id:"jinjidu",
								     selectOnFocus:true,
									 queryMode: 'local',
							        forceSelection: true,  
//									 hidden : true ,
									 name: 'nanyi',
									 store :Ext.create('Ext.data.Store', {
												    fields: ['id','name'],
												    data : [
												        {"id":1, "name":"一级"},
		       										    {"id":2, "name":"二级"},
		      										    {"id":3, "name":"三级"},
		       										    {"id":4, "name":"四级"}
												        ]
										 		}),
									 displayField: 'name',
	    							 valueField: 'id',
	    							 listeners:{   
												select:function(combo,record,index){
													 try{
															 var parent=Ext.getCmp('fen');
															 parent.clearValue();
															 parent.store.load({params:{param:this.value}});
														 }
													 catch(ex){
																 Ext.MessageBox.alert("错误","数据加载失败。");
															 }
													}
											}
							          	        	
								},{
									 columnWidth :.40,
									 layout : "form",
									 emptyText:'请选择得分',
									 fieldLabel: '项目分数',
									 id:'fen',
									 xtype:"combobox",
								     labelAlign :"right",
								     selectOnFocus:true,
									 queryMode: 'local',
									 name: 'core',
									 forceSelection: true,  
									 store :"CoreStore",
									 displayField: 'core',
	    							 valueField: 'core'
	    							 
      	        	    
								}]	
			   		 }]
		 })
			var win = new Ext.Window({
				title : "修改工作",
				width : 700,
				height : 300,
				frame:true,
				layout:'fit',
				items : [ myform1
							],
				buttons : [{
							text : "确定",
							handler : function() {
								win.getComponent(0).getForm().submit({
											    url : 'job_editJob',
										  success : function() {
												Ext.Msg.alert('提示', '修改成功');
												win.close();
											 grid.getStore().reload();
											},
											failure : function() {
												Ext.Msg.alert('错误', '修改失败');
											},
											waitMsg : "请稍后，正在保存。。。。"
	
										});
							}
						}, {
							text : "重置",
							handler : function() {
								win.getComponent(0).getForm().reset();
							}
						}, {
							text : "取消",
							handler : function() {
												win.close();
											
							}
						}]
			});
		
		var selections = grid.getSelectionModel().getSelection();
						if(selections.length==0){
							Ext.MessageBox.alert("提示","请选择要编辑的一行！");
						}else if (selections.length > 1) {
							Ext.MessageBox.alert("提示", "请检查您是否选中了多行！");
							return;
						} else{
							var record = selections[0];
						//这里是修改操作的实现部分
							win.getComponent(0).getForm().loadRecord(record);
							win.show();
						}
 }
 
 	function deletJob(){
				 var grid=this.ownerCt.ownerCt;
			     var selections = grid.getSelectionModel().getSelection();
					if(selections){
					if(selections.length==0){
							Ext.MessageBox.alert("提示","请检查是否选中某一行！");
						}else if (selections.length > 1) {
							Ext.MessageBox.alert("提示", "请检查您是否选中了多行！");
							return;
						} else{
							Ext.MessageBox.confirm("提示", "确认要删除 ？", function(btn) {
							if (btn == 'yes') {			
							var record = selections[0];
								Ext.Ajax.request({
										url : 'job_delete',
										success : function() {
											Ext.MessageBox.alert("提示",
													"删除" + record.get("name")+ "成功！");
											    grid.getStore().remove(selections );
											    grid.getStore().reload();
										},
										failure : function() {
											Ext.MessageBox.alert("提示", "项目有具体工作内容，删除失败！");
										},
										params : {
											id : record.get("id")
										}
									});			
								}
					  	})
                   	} 
		   }				
	}
	function searchJob(){
			var grid=this.ownerCt.ownerCt;
			var date= Ext.getCmp('searchjob_999').getValue();
			Ext.Ajax.request({
					url : 'job_saercherJob',
					success : function() {
							  grid.getStore().on('beforeload', function (store, options) {
                              var new_params = {searchdate:Ext.util.Format.date(date, 'Y-m')}
                                    Ext.apply(store.proxy.extraParams, new_params);
                           });//此处为加载条件
							  grid.getStore().reload();
						},
					failure : function() {
							Ext.MessageBox.alert("提示", "查询失败！");
									}
				});		
		
			
		}
	 	